import 'package:json_annotation/json_annotation.dart';

import '../../../util/DateUtil.dart';
import '../base/Req.dart';

part 'WebRtcData.g.dart';

// 邀请语音请求
class WebRtcInvitationReq extends Req {
  String? fromUserId;
  String roomName;
  ChatType chatType;
  Set<String> userIds;

  WebRtcInvitationReq({ this.fromUserId, required this.roomName, required this.chatType, required this.userIds});

  factory WebRtcInvitationReq.fromJson(Map<String, dynamic> map) =>_$WebRtcInvitationReqFromJson(map);

  Map<String, dynamic> toJson() => _$WebRtcInvitationReqToJson(this);
}

class InvitationResultList {
  List<InvitationResult> invitationResultList;

  InvitationResultList({ required this.invitationResultList});

  factory InvitationResultList.fromJson(Map<String, dynamic> map) =>_$InvitationResultListFromJson(map);

  Map<String, dynamic> toJson() => _$InvitationResultListToJson(this);

}

class InvitationResult {
  String userId;
  bool isOffline;
  bool isReject;

  InvitationResult({ required this.userId, required this.isOffline, required this.isReject});

  factory InvitationResult.fromJson(Map<String, dynamic> map) =>_$InvitationResultFromJson(map);

  Map<String, dynamic> toJson() => _$InvitationResultToJson(this);
}

// 邀请应答回复
class WebRtcInvitationResultReq extends Req {
  String toUserId;
  bool isAccept;

  // 拒绝原因
  String? reason;

  WebRtcInvitationResultReq({ required this.toUserId, required this.isAccept, this.reason});

  factory WebRtcInvitationResultReq.fromJson(Map<String, dynamic> map) =>_$WebRtcInvitationResultReqFromJson(map);

  Map<String, dynamic> toJson() => _$WebRtcInvitationResultReqToJson(this);
}

class WebRtcCancelReq extends Req {
  Set<String> userIds;

  WebRtcCancelReq({ required this.userIds});

  factory WebRtcCancelReq.fromJson(Map<String, dynamic> map) =>_$WebRtcCancelReqFromJson(map);

  Map<String, dynamic> toJson() => _$WebRtcCancelReqToJson(this);
}

enum ChatType {
  audio(1, "语音聊天"),        // 语言聊天
  video(2, "视频聊天"),        // 视频聊天
  sharing(3, "共享资料"),      // 共享资料
  ;

  final int value;
  final String desc;

  const ChatType(this.value, this.desc);

  static ChatType ofValue(int value) {
    return ChatType.values.firstWhere((element) => element.value == value);
  }
}